<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="108px">
      <el-form-item label="设备名称" prop="deviceName">
        <el-input v-model="queryParams.deviceName" placeholder="请输入设备名称" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="设备类型" prop="deviceType">
        <el-select v-model="queryParams.deviceType" clearable filterable placeholder="请选择设备名称">
          <el-option v-for="dict in dict.type.deviceType_type" :key="dict.value" :label="dict.label"
            :value="parseInt(dict.value)" size="small">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="设备编码" prop="deviceCode">
        <el-input v-model="queryParams.deviceCode" placeholder="请输入设备编码" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="分配模式" prop="bindMode">
        <el-select v-model="queryParams.bindMode" clearable filterable placeholder="请选择分配模式" @change="changems">
          <el-option v-for="dict in dict.type.radio_type" :key="dict.value" :label="dict.label"
            :value="parseInt(dict.value)" size="small">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="学生" prop="relationId" v-if="queryParams.bindMode == 0">
        <el-select v-model="queryParams.relationId" clearable filterable placeholder="请选择学生">
          <el-option v-for="item in namelist" :key="item.value" :label="item.label" :value="parseInt(item.value)"
            size="small">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="班级" prop="relationId" v-if="queryParams.bindMode == 1">
        <el-select v-model="queryParams.relationId" clearable filterable placeholder="请选择班级">
          <el-option v-for="item in classList" :key="item.id" :label="item.label" :value="parseInt(item.id)" size="small">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-button type="primary" size="mini" @click="downloadTemplate">下载模板</el-button>
    <el-button size="mini" @click="upload.open = true">批量导入</el-button>
    <el-row :gutter="10" class="mb8">
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="warning"-->
      <!--          icon="el-icon-circle-close"-->
      <!--          size="mini"-->
      <!--          :disabled="multiple"-->
      <!--          @click="handleDelete"-->
      <!--        >删除</el-button>-->
      <!--      </el-col>-->
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="info"-->
      <!--          icon="el-icon-upload2"-->
      <!--          size="mini"-->
      <!--          @click="handleImport"-->
      <!--          v-hasPermi="['base:student:import']"-->
      <!--        >导入</el-button>-->
      <!--      </el-col>-->

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="studentList" @selection-change="handleSelectionChange">
      <!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="设备名称" align="center" prop="deviceName" />
      <el-table-column label="设备类型" align="center" prop="deviceType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.deviceType_type" :value="scope.row.deviceType" />
        </template>
      </el-table-column>
      <el-table-column label="分配模式" align="center" prop="bindMode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.radio_type" :value="scope.row.bindMode" />
        </template>
      </el-table-column>
      <el-table-column label="分配对象" align="center" prop="relationName">
        <template slot-scope="scope">
          <div v-if="scope.row.bindMode == 2">本园</div>
          <div v-else>{{ scope.row.relationName }}</div>
        </template>
      </el-table-column>

      <!--      <el-table-column label="设备SN" align="center" prop="deviceSn"/>-->
      <el-table-column label="设备编码" align="center" prop="deviceCode" />
      <el-table-column label="设备状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.devicestatus_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="学校代码" align="center" prop="schoolCode" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">绑定</el-button>

          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleUnbind(scope.row)">清除绑定</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- 当设备类型为1,2,3,4提示 -->
    <el-dialog  :close-on-click-modal="false" :title="title" :visible.sync="isRemindOpen" width="500px" append-to-body>
      <div>确认将该设备绑定到{{ $store.getters.schoolName }}吗?</div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="remindOPenSubmit">确 定</el-button>
        <el-button @click="isRemindOpen = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改学生对话框 -->
    <el-dialog  :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-tabs type="card">
          <el-form-item label="班级" prop="classId"  v-if="form.deviceType == 7 || form.deviceType == 8">
            <el-select v-model="form.classId" clearable filterable placeholder="请选择班级" @change="getStuchange">
              <el-option v-for="item in classList" :key="item.id" :label="item.label" :value="item.id + ''" size="small">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="学生" prop="relationId" v-if="form.deviceType == 7 || form.deviceType == 8">
            <el-select v-model="form.relationId" clearable filterable placeholder="请选择学生">
              <el-option v-for="item in namelist" :key="item.value" :label="item.label" :value="item.value + ''"
                size="small">
              </el-option>
            </el-select>
            <input type="hidden" v-model="form.bindMode = 0" />
          </el-form-item>

          <el-row v-else-if="form.deviceType == 10">
            <input type="hidden" v-model="form.bindMode = 3" />
            <el-form-item label="区角位置">
              <el-select v-model="form.corner" clearable filterable placeholder="请选择区角位置" @change="seletCornerList">
                <el-option v-for="item in devicescope" :key="item.value" :label="item.label" :value="item.value"
                  size="small">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="区角内容" prop="relationId" v-if="form.corner == 2">
              <el-select v-model="form.relationId" clearable filterable placeholder="请选择区角内容">
                <el-option v-for="item in publicCorner" :key="item.id" :label="item.cornerName" :value="item.id"
                  size="small">
                </el-option>
              </el-select>
            </el-form-item>
            <el-row v-else-if="form.corner == 1">
              <el-form-item label="班级">
                <el-select v-model="form.classId" clearable filterable placeholder="请选择班级" @change="seletCornerClassList">
                  <el-option v-for="item in classList" :key="item.id" :label="item.label" :value="item.id" size="small">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="区角内容" prop="relationId">
                <el-select v-model="form.relationId" clearable filterable placeholder="请选择区角内容">
                  <el-option v-for="item in classCorner" :key="item.id" :label="item.cornerName" :value="item.id"
                    size="small">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-row>
          </el-row>
          <el-form-item label="班级" prop="relationId"  v-else-if="form.deviceType == 5 || form.deviceType == 6 || form.deviceType == 9">
            <input type="hidden" v-model="form.bindMode = 1" />
            <el-select v-model="form.relationId" clearable filterable placeholder="请选择班级">
              <el-option v-for="item in classList" :key="item.id" :label="item.label" :value="item.id + ''" size="small">
              </el-option>
            </el-select>
          </el-form-item>
          <div v-else>
            <input type="hidden" v-model="form.bindMode = 2" />
            <el-input type="hidden" v-model="form.relationId = schoolCode" />
          </div>
          <!--          <el-form-item label="设备地址" prop="deviceAdress">-->
          <!--            <el-input type="text" v-model="form.deviceAdress"/>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="设备SN" prop="deviceSn">-->
          <!--            <el-input type="text" v-model="form.deviceSn"/>-->
          <!--          </el-form-item>-->
          <!-- <el-form-item label="设备状态" prop="status">
            <el-select v-model="form.status" placeholder="请选择设备状态">
              <el-option v-for="dict in dict.type.devicestatus_status" :key="dict.value" :label="dict.label"
                :value="parseInt(dict.value)" size="small">
              </el-option>
            </el-select>
          </el-form-item> -->
          <!--          <el-form-item label="学校编码" prop="schoolCode">-->
          <!--            <el-input-->
          <!--              v-model="form.schoolCode"-->
          <!--              placeholder="请输入学校编码"-->
          <!--              size="small"-->
          <!--            />-->
          <!--          </el-form-item>-->

        </el-tabs>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm()">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 导入对话框 -->
    <el-dialog  :close-on-click-modal="false" :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
        :action="upload.url" :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <!-- <div class="el-upload__tip" slot="tip">
          <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的学生数据
          <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
        </div> -->
        <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 下载模板弹窗-->
    <el-dialog  :close-on-click-modal="false" title="下载模板" :visible.sync="downloadOpen" width="450px" append-to-body @close="cancelDownload"  >
      <el-form :model="ruleForm" :rules="downloadRules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
        <el-form-item label="年级" prop="year">
          <el-select v-model="ruleForm.year" clearable filterable placeholder="请选择年级" @change="getqueryFormclassList">
            <el-option v-for="dict in dict.type.year_type" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="班级" prop="classId">
          <el-select v-model="ruleForm.classId" :disabled='isClassDisabled' clearable filterable placeholder="请选择班级">
            <el-option v-for="item in classList" :key="item.id" :label="item.label" :value="item.id" size="small">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="选择设备类型" prop="deviceType">
          <el-select v-model="ruleForm.deviceType" clearable filterable placeholder="请选择设备类型">
            <el-option v-for="item in downloadDeviceType" :key="item.id" :label="item.label" :value="item.id"
              size="small">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addDownload">下 载</el-button>
        <el-button @click="cancelDownload">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { disableStudent, enableStudent, exportStudent, importTemplate, exportTemplate } from "@/api/base/student";
import {
  selectDevice,
  selectName,
  listYdevice,
  selectRoom,
  updateYdevicerecord,
  addYdevicerecord,
  delYdevicerecord, unbindYdevicerecord, cornerPublic, cornerClass
} from '@/api/base/device'
import { selectClazz } from '@/api/base/clazz'
import { getToken } from "@/utils/auth";
import { mapGetters } from 'vuex'

export default {
  name: "Student",
  dicts: ['deviceType_type', 'devicestatus_status', 'devicestatus_status', 'radio_type', 'year_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 班级表格数据
      queryClazzList: [],
      // 学生表格数据
      studentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      isRemindOpen: false,
      // 导入参数
      upload: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/base/Ydevicerecord/importData"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        schoolCode: this.$store.getters.schoolCode,
        relationId: '',
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        deviceName: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        userName: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        className: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        // deviceType: [
        //   { required: true, message: "不能为空", trigger: "blur" }
        // ],
        // status: [
        //   { required: true, message: "不能为空", trigger: "blur" }
        // ],
        // schoolCode: [
        //   { required: true, message: "不能为空", trigger: "blur" }
        // ],
        roomName: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
      },
      useStatus: [{ label: '公用设备', value: 0 }, { label: '个人用设备', value: 1 }],
      deviceList: [],//设备名称列表
      namelist: [],//用户列表
      classList: [],
      devicescope: [{ label: '班级', value: 1 }, { label: '公共', value: 2 },{label:'功能教室',value:"3"}],//区角位置
      publicCorner: [],//公共区角
      classCorner: [],//班级区角
      downloadOpen: false, //下载模板弹窗
      ruleForm: {
        classId: null
      },
      downloadRules: {
        year: [
          { required: true, message: "年级不能为空", trigger: "blur" }
        ],
        classId: [
          { required: true, message: "班级不能为空", trigger: "blur" }
        ],
        deviceType: [
          { required: true, message: "设备类型不能为空", trigger: "blur" }
        ],
      },
      isClassDisabled: true,
      downloadDeviceType: [
        {
          id: 7,
          label: '手环',
        },
        {
          id: 8,
          label: '睡眠带',
        },
      ]
    };
  },
  computed: {
    ...mapGetters(['schoolCode']),
  },
  created() {
    //用户名
    this.getNamelist()
    this.getList();
    //班级
    this.getQueryClazzList();
    //设备名称
    // this.getDeviceList()
  },
  mounted() {

  },
  methods: {
    async  getStuchange(){
      try {
        const obj ={
                 schoolCode:this.queryParams.schoolCode,
                 classId:this.queryParams.classId||this.form.classId
               }
        const data = await selectName(obj)

        this.namelist = data.rows.map(item => {
          return {
            label: item.name,
            value: item.id,
          }
        })
      } catch (e) {
        console.log(e)
      }
    },
    /**班级*/
    async getqueryFormclassList() {
      this.isClassDisabled = true
      this.ruleForm.classId = null
      try {
        let params = {}
        this.ruleForm.classId = ''
        if (this.ruleForm.year) params.year = this.ruleForm.year;
        const { rows } = await selectClazz(params);
        if (rows.length && this.ruleForm.year) {
          this.isClassDisabled = false
        }
        this.classList = rows.map(item => {
          return {
            id: item.id,
            label: item.title,
          }
        })
      } catch (e) {
        console.log(e)
      }
    },
    downloadTemplate() {
      this.downloadOpen = true
    },
    cancelDownload() {
      this.downloadOpen = false;
      this.$refs[ruleForm].resetFields();
    },
    addDownload() {
      this.$refs["ruleForm"].validate(async valid => {
        if (valid) {
          const { code, msg } = await exportTemplate(this.ruleForm)
          if (code === 200) {
            this.download(msg);
            this.downloadOpen = false;
            this.$refs[ruleForm].resetFields();
            this.$message.message('操作成功')
          }else{
            this.$message.error(msg)
          }
        }
      });
    },
    /**公共区角下拉**/
    seletCornerList(val) {
      this.form.relationId = null
      if (val == 2) {
        this.form.classId = null
        this.getCornerList(val)
      }
    },
    /***班级区角下拉*/
    seletCornerClassList(val) {
      this.getCornerClass(val)
    },
    /**获取班区角**/
    async getCornerClass(val) {
      try {
        let params = {
          classId: val,
          cornerModel: 1,
        }
        const data = await cornerClass(params)
        this.classCorner = data.rows
      } catch (e) {
        console.log(e)
      }
    },
    /**获取公共区角**/
    async getCornerList(val) {
      try {
        const data = await cornerPublic({ cornerModel: val })
        this.publicCorner = data.rows
      } catch (e) {
        console.log(e)
      }
    },
    /* 分配模式切换 */
    changems() {
      this.queryParams.relationId = ''
    },
    /**查询用户列表*/
    async getNamelist() {
      try {
        this.loading = true;

        const data = await selectName()

        this.namelist = data.rows.map(item => {
          return {
            label: item.name,
            value: item.id,
          }
        })
      } catch (e) {
        console.log(e)
      }

    },
    /**查询设备列表*/
    // async getDeviceList(){
    //   try {
    //     this.loading = true;
    //     const data=await selectDevice()
    //     this.deviceList=data.rows.map(item=>{
    //       return{
    //         label:item.deviceName,
    //         value:item.id,
    //       }
    //     })
    //   }catch (e) {
    //     console.log(e)
    //   }
    // },
    /** 查询学生列表 */
    async getList() {
      try {
        this.loading = true;
        const data = await listYdevice(this.queryParams);
        this.studentList = data.rows;
        this.total = data.total;
        this.loading = false;
      } catch (e) {
        console.log(e)
      }

    },

    /** 查询班级列表 */
    async getQueryClazzList() {
      try {
        this.loading = true;
        const { rows } = await selectClazz();
        this.classList = rows.map(item => {
          return {
            id: item.id,
            label: item.title,
          }
        })
        this.loading = false;
      } catch (e) {
        console.log(e)
      }
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.getStuchange()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        deviceId: null,
        deviceName: null,
        userId: null,
        userName: null,
        classId: null,
        roomName: null,
        deviceType: null,
        status: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        schoolCode: this.$store.getters.schoolCode,
        relationId: '',
      },
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加设备管理";
    },
    /* 清除绑定 */
    async handleUnbind(row) {
      try {
        const id = row.id || this.ids
        let params = {
          id: id
        }
        this.$confirm('是否确认清除编号为"' + row.deviceName + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return unbindYdevicerecord(params);
        }).then(() => {
          this.msgSuccess("清除成功");
          this.getList();
        })
        //
        // const data=await unbindYdevicerecord(params)
        // this.msgSuccess(data.msg);
        // this.getList();
      } catch (e) {
        console.log(e)
      }
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      console.log(row)
      this.reset();
      const id = row.id || this.ids
      this.form = Object.assign({}, this.form, row)
      this.$set(this.form,'relationId',row.relationId)
      if (row.deviceType == 1 || row.deviceType == 2 || row.deviceType == 3 || row.deviceType == 4) {
        this.isRemindOpen = true
        this.title = '提示'
      } else {
        this.open = true;
        this.title = "修改设备管理";
      }
    },
    remindOPenSubmit() {
      updateYdevicerecord(this.form).then(response => {
        if (response.code == 200) {
          this.msgSuccess("修改成功");
          this.isRemindOpen = false;
          this.getList();
        } else {
          this.msgError(response.msg);
        }

      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if(this.form.corner == 3){
                this.form.relationId = this.$store.getters.schoolCode
                this.form.bindMode = 2
          }
          if (this.form.id != null) {
            if ((this.form.deviceType == 7 || this.form.deviceType == 8) && !this.form.relationId) {
              this.msgWarning("学生不能为空");
            } else if (this.form.deviceType == 10 && !this.form.corner) {
              this.msgWarning("区角位置不能为空");
            } else if ((this.form.deviceType == 5 || this.form.deviceType == 6 || this.form.deviceType == 9) && !this.form.relationId) {
              this.msgWarning("班级不能为空");
            } else if (this.form.deviceType == 10 && this.form.corner == 1 && !this.form.relationId) {
              this.msgWarning("班级和区角内容不能为空");
            } else if (this.form.deviceType == 10 && this.form.corner == 2 && !this.form.relationId) {
              this.msgWarning("区角内容不能为空");
            }else {
              updateYdevicerecord(this.form).then(response => {
                if (response.code == 200) {
                  this.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                } else {
                  this.msgError(response.msg);
                }
              });
            }

          } else {
            addYdevicerecord(this.form).then(response => {
              if (response.code == 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
                this.getStuchange()
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delYdevicerecord(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出选中的学生数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportStudent(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "导入学生";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      importTemplate().then(response => {
        this.download(response.msg);
      });
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
